package EA.testproblems;
import EA.*;

/*
  Easom function

  Created: 29. sept. 1999
  @version 1.0
  @author Rene Thomsen
cos(x)*cos(y)*exp((-((x-pi)**2)-(((y-pi)**2))))
*/

public class Easom extends NumericalProblem 
{

  // Easier way to build max and min
    private double[][] lmax = new double[0][2];
    private double[][] lmin = {{Math.PI,Math.PI}};

    public Easom()
    {
      super();

      double[] optimas;

      name = "Easom function";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return -Math.cos(realpos[0])*Math.cos(realpos[1])*Math.pow(Math.E,(-Math.pow((realpos[0]-Math.PI),2)-(Math.pow(realpos[1]-Math.PI,2))));
	      };
	  };

      dimensions = 2;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-100, 100);
      intervals[1] = new Interval(-100, 100);
      
      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmax[i][0];
	optimas[1] = lmax[i][1];
	knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmin[i][0];
	optimas[1] = lmin[i][1];
	knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
      }
    }
}
